package cn.page;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

@WebListener
public class LoginUserNumberListener implements HttpSessionAttributeListener {

	private int num; 

	public LoginUserNumberListener() {
	}
	public void attributeAdded(HttpSessionBindingEvent event) {
		ServletContext context = event.getSession().getServletContext();
		if ("loginUser".equals(event.getName())){
			num++;
			context.setAttribute("loginUserNum", num);
		}
	}
	public void attributeRemoved(HttpSessionBindingEvent event) {
		ServletContext context = event.getSession().getServletContext();
		if ("loginUser".equals(event.getName())){
			num--;
			context.setAttribute("loginUserNum", num);
		}
	}

	public void attributeReplaced(HttpSessionBindingEvent event) {
		// TODO Auto-generated method stub
	}

}